const decodeString = (s) => {
  const numStack = [];
  const strStack = [];
  let result = "";
  let num = 0;
  for (const char of s) {
    if (!isNaN(char)) {
      num = num * 10 + Number(char);
    } else if (char === "[") {
      numStack.push(num);
      num = 0;
      strStack.push(result);
      result = "";
    } else if (char === "]") {
      const repeatTimes = numStack.pop();
      result = strStack.pop() + result.repeat(repeatTimes);
    } else {
      result += char;
    }
  }
  return result;
};
